package com.adnaan;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * 启动程序
 */
@Slf4j
@SpringBootApplication
@ServletComponentScan
public class AdnaanApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext context = SpringApplication.run(AdnaanApplication.class, args);
        Environment env = context.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        String activeProfiles = Arrays.toString(env.getActiveProfiles());

        log.info("\n----------------------------------------------------------\n" +
                        "  Adnaan 多模块脚手架启动成功！\n" +
                        "  环境: \t{}\n" +
                        "  访问地址: \thttp://{}:{}{}\n" +
                        "  Swagger文档: \thttp://{}:{}{}swagger-ui/index.html\n" +
                        "  Druid监控: \thttp://{}:{}{}druid\n" +
                        "  文档地址: http://localhost:{}/doc.html\n" +
                        "----------------------------------------------------------",
                activeProfiles.isEmpty() ? "default" : activeProfiles,
                ip, port, path,
                ip, port, path,
                ip, port, path,
                port);
    }
} 